/*
     Copyright (C) 2011 Benny Mackney

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "PlayerSimple.h"

PlayerSimple::PlayerSimple()
{
    //ctor
    speed = 4;
}

PlayerSimple::~PlayerSimple()
{
    //dtor
}

void PlayerSimple::handle_keyevent(const SDL_Event &event){
    SDLKey key = event.key.keysym.sym;
    Uint8 type = event.key.type;
    if(key == SDLK_w){
        if(type == SDL_KEYDOWN) movement.set_y(-speed);
        else if(movement.get_y() < 0) movement.set_y(0);
    }else if( key == SDLK_s){
        if(type == SDL_KEYDOWN) movement.set_y(speed);
        else if(movement.get_y() > 0) movement.set_y(0);
    }else if(key == SDLK_a){
        if(type == SDL_KEYDOWN) movement.set_x(-speed);
        else if(movement.get_x() < 0) movement.set_x(0);
    }else if( key == SDLK_d){
        if(type == SDL_KEYDOWN) movement.set_x(speed);
        else if(movement.get_x() > 0) movement.set_x(0);
    }

}

void PlayerSimple::tick(){
    boxRect.x += movement.get_x();
    boxRect.y += movement.get_y();
}
